/**
 * Copyright (C) 2013 Fabien Fleurey <fabien@fleurey.com>
 */
package com.fleurey.android.light.flashmanager;

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;

public class FlashManager {

	private Camera camera=null;

	public static boolean isFlashAvailable(Context context) {
		return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
	}

	public void turnFlashON()
	{
		if (camera == null) {
			camera = Camera.open();
			Parameters parameters = camera.getParameters();
			parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
			camera.setParameters(parameters);
			camera.startPreview();
		}
	}

	public void turnFlashOFF() {
		if (camera != null) {
			camera.stopPreview();
			camera.release();
			camera = null;
		}
	}
}
